package com.dingpeikeji.quickdeer.modules.rentprod.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dingpeikeji.quickdeer.core.common.persistence.Page;
import com.dingpeikeji.quickdeer.core.common.service.CrudService;
import com.dingpeikeji.quickdeer.modules.rentprod.entity.TRentprod;
import com.dingpeikeji.quickdeer.modules.rentproduct.entity.TRentprodPrice;
import com.dingpeikeji.quickdeer.modules.rentproduct.service.TRentprodPriceService;
import com.dingpeikeji.quickdeer.modules.rentprod.dao.TRentprodDao;

/**
 * 整车调价Service
 * @author mash
 * @version 2017-03-16
 */
@Service
@Transactional(readOnly = true)
public class TRentprodService extends CrudService<TRentprodDao, TRentprod> {
	
	@Autowired
	private TRentprodPriceService tRentprodPriceService;

	public TRentprod get(String id) {
		return super.get(id);
	}
	
	public List<TRentprod> findList(TRentprod tRentprod) {
		return super.findList(tRentprod);
	}
	
	public Page<TRentprod> findPage(Page<TRentprod> page, TRentprod tRentprod) {
		return super.findPage(page, tRentprod);
	}
	
	@Transactional(readOnly = false)
	public void save(TRentprod tRentprod) {
		super.save(tRentprod);
		TRentprodPrice tPrice = new TRentprodPrice();
//		tPrice.setRentprodid(Integer.parseInt(tRentprod.getRentprodid()));
		tPrice.setSuitrtnprice(100.0);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			tPrice.setEfftdate(sdf.parse("2000-01-01"));
			tPrice.setInvaliddate(sdf.parse("2099-12-31"));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		tRentprodPriceService.save(tPrice);
		
	}
	
	@Transactional(readOnly = false)
	public void delete(TRentprod tRentprod) {
		super.delete(tRentprod);
	}
	
}